package edu.ntnu.superrss.models;

import com.sun.syndication.feed.impl.CopyFromHelper;
import com.sun.syndication.feed.impl.ObjectBean;
import com.sun.syndication.feed.synd.SyndContent;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.*;

/**
 * This is close to a Exact copy of SyndContentImpl from ROME, with hibernate annotations.
 * @author Sigurd Fosseng <sigurd at fosseng.net>
 */
@Entity
@Table(name="CONTENT")
public class SyndContentImpl implements  Serializable, SyndContent {
	private ObjectBean objBean;
	private String type;
	private String value;
	private String mode;
	private Long id;
	@Id
	@GeneratedValue
	@Column(name="CONTENT_ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public SyndContentImpl() {
		objBean = new ObjectBean(SyndContent.class, this);
	}

	@Override
	public Object clone() throws CloneNotSupportedException{
		return objBean.clone();
	}

	@Override
	@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
	public boolean equals(Object other){
		return objBean.equals(other);
	}
	@Override
	public int hashCode(){
		return objBean.hashCode();
	}

	public String getType() {
		return type;
	}
	@Override
	public String toString(){
		return objBean.toString();
	}

	public void setType(String type) {
		this.type=type;
	}

	public String getMode() {
		return mode;
	}

	public void setMode(String mode) {
		this.mode = mode;
	}

	@Column(name="Val",length=Integer.MAX_VALUE)
	@Lob
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
	@Transient
	public Class getInterface() {
		return SyndContent.class;
	}


      //Utilizes COPY_FROM_HELPER from the rome API. 
	public void copyFrom(Object obj) {
		COPY_FROM_HELPER.copy(this, obj);
	}
	private static final CopyFromHelper COPY_FROM_HELPER;
      
      //Declares the implementations the helper should copy into.
	static {
		Map basePropInterfaceMap = new HashMap();
		basePropInterfaceMap.put("type",String.class);
		basePropInterfaceMap.put("value",String.class);
		basePropInterfaceMap.put("mode", String.class);

		Map basePropClassImplMap = Collections.EMPTY_MAP;
		COPY_FROM_HELPER = new CopyFromHelper(SyndContent.class,basePropInterfaceMap,basePropClassImplMap);
	}
}
